//
//  PlatformProductTypeListCell.m
//  HAODE
//
//  Created by panquanReabam.com on 15/11/2.
//  Copyright © 2015年 reabam.com. All rights reserved.
//

#import "PlatformProductTypeListCell.h"

#import "UIImageView+WebCache.h"
#import "UIButton+WebCache.h"
#import "HttpRequest.h"
#import "UIViewExt.h"
#import "PlatformCollectionViewCell.h"
#define ScreenHeight [UIScreen mainScreen].bounds.size.height
#define ScreenWidth  [UIScreen mainScreen].bounds.size.width

@interface PlatformProductTypeListCell ()<UICollectionViewDataSource,UICollectionViewDelegate>
{
    NSArray *array;
    NSInteger collectionHeight;
    UIView *containerView;
    UICollectionView *collection;
  
}
@end
@implementation PlatformProductTypeListCell{
    
    
}

- (void)awakeFromNib {
    
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _imageArrayname.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *str = @"collection";
    PlatformCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:str forIndexPath:indexPath];

    for (UIView *view in [cell subviews]){
        [view removeFromSuperview];
    }
    UIButton* image=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, cell.width, cell.height)];
    image .titleLabel.font=[UIFont systemFontOfSize:13];
    image.layer.borderWidth = 0.40;
    image.layer.borderColor = qianhuiColor.CGColor;
    if ([_imageArrayname[indexPath.row]isEqualToString:self.content]) {
        [image setBackgroundImage:[UIImage imageNamed:@"leibiegouxuan"] forState:UIControlStateNormal];

    }
    [image setTitle:_imageArrayname[indexPath.row] forState:UIControlStateNormal];
    [image setTitleColor:zhonghuiColor forState:UIControlStateNormal];
    image.userInteractionEnabled=NO;
    [cell addSubview:image];
    

    return cell;
}

#define kYOfImageContainer   136.0

- (void)setComment:(MCirclemodel *)comment
{
    _comment = comment;
     _imageArrayname= comment.typeName;
     _imageArraycode= comment.typeCode;
    self.diselabelview.layer.borderWidth = 0.40;
    self.diselabelview.layer.borderColor = qianhuiColor.CGColor;
    self.nameLabel.text = comment.userName;
       [collection removeFromSuperview];
    
    UILabel *quan = [[UILabel alloc]initWithFrame:CGRectMake(10, 15, 15, 15)];
    quan.textColor = luseColor;
    quan.text=@"o";
    quan.font=[UIFont boldSystemFontOfSize:15];
    [self.contentView addSubview:quan];

    UIImageView *_xianview = [[UIImageView alloc]initWithFrame:CGRectMake(10,50-0.5, ScreenWidth-20, 0.5)];
    _xianview.image=[UIImage imageNamed:@"hengxian"];
    [self.contentView addSubview:_xianview];

    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    layout.itemSize = CGSizeMake((ScreenWidth-45)/4 , 30);
    layout.minimumInteritemSpacing = 1;
    layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    [collection removeFromSuperview];
    
    for (int i = 0,j = 0; i < comment.typeName.count; i++) {
        if (i % 4 == 0) {
            j++;
        }
         collectionHeight = (j+1) *30;
    }

    collection = [[UICollectionView alloc]initWithFrame:CGRectMake(12.5, 60, ScreenWidth-25, collectionHeight) collectionViewLayout:layout];
    collection.backgroundColor = [UIColor whiteColor];
    collection.alwaysBounceVertical = YES;
    [collection registerClass:[PlatformCollectionViewCell class] forCellWithReuseIdentifier:@"collection"];
    collection.delegate = self;
    collection.dataSource = self;
    collection.pagingEnabled=YES;
    if (comment.typeName.count>0) {
         [self.contentView addSubview:collection];
    }else{
    
    }
    
}



- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
//    commdity.code=_imageArraycode[indexPath.row];
//    commdity.content=_imageArrayname[indexPath.row];
//    [_mDelegate tiaojiemian1:_imageArrayname[indexPath.item]];//跳回控制器
    [_mDelegate code:_imageArraycode[indexPath.row] content:_imageArrayname[indexPath.item]];

    
}
- (void)collectionView:(UICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath{


}
- (void)collectionView:(UICollectionView *)colView  didUnhighlightItemAtIndexPath:(NSIndexPath *)indexPath
{

    
}


@end
